package com.hoshiicloud.user.param.rbac;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hoshiicloud.common.query.PageParam;
import com.hoshiicloud.rbac.entity.SysPermissiones;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * <p>
 * 查询权限参数
 * </p>
 * 
 * @author Mr.Wu
 * @since 2019-04-27
 */
@Data
public class SysPermissionesQueryParam extends PageParam implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * id
	 */
	@ApiModelProperty(value = "id")
	private Long id;

	/**
	 * 所属系统
	 */
	@ApiModelProperty(value = "所属系统")
	private Long systemId;

	@ApiModelProperty(value = "关联系统id")
	private Long refId;

	@ApiModelProperty(value = "关联系统类型")
	private String refType;

	/**
	 * 所属上级
	 */
	@ApiModelProperty(value = "所属上级")
	private Long pId;

	/**
	 * 名称
	 */
	@ApiModelProperty(value = "名称")
	private String name;

	/**
	 * 类型(1:目录,2:菜单,3:按钮)
	 */
	@ApiModelProperty(value = "类型(1:目录,2:菜单,3:按钮)")
	private Integer type;

	/**
	 * 权限值
	 */
	@ApiModelProperty(value = "权限值")
	private String permissionValue;

	/**
	 * 路径
	 */
	@ApiModelProperty(value = "路径")
	private String uri;

	/**
	 * 图标
	 */
	@ApiModelProperty(value = "图标")
	private String icon;

	/**
	 * 状态(0:禁止,1:正常)
	 */
	@ApiModelProperty(value = "状态(0:禁止,1:正常)")
	private Integer status;

	/**
	 * 排序
	 */
	@ApiModelProperty(value = "排序")
	private Long orders;

	public QueryWrapper<SysPermissiones> convertToQueryWrapper() {
		QueryWrapper<SysPermissiones> queryWrapper = new QueryWrapper<SysPermissiones>();
		queryWrapper.eq(this.getId() != null, "id", this.getId());
		queryWrapper.eq(this.getSystemId() != null, "system_id", this.getSystemId());
		queryWrapper.eq(this.getPId() != null, "p_id", this.getPId());
		queryWrapper.eq(this.getRefId()!=null,"ref_id",this.getRefId());
		queryWrapper.eq(StringUtils.isNotBlank(this.refType),"ref_type",this.getRefType());
		queryWrapper.eq(StringUtils.isNotBlank(this.getName()), "name", this.getName());
		queryWrapper.eq(this.getType() != null, "type", this.getType());
		queryWrapper.eq(StringUtils.isNotBlank(this.getPermissionValue()), "permission_value", this.getPermissionValue());
		queryWrapper.eq(StringUtils.isNotBlank(this.getUri()), "uri", this.getUri());
		queryWrapper.eq(StringUtils.isNotBlank(this.getIcon()), "icon", this.getIcon());
		queryWrapper.eq(this.getStatus() != null, "status", this.getStatus());
		queryWrapper.orderByDesc("orders");
		return queryWrapper;
	}
}
